-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try: Set show_in_rest
to true
by default when label
argument is defined
#7302
Try: Set show_in_rest
to true
by default when label
argument is defined
#7302
Conversation
@@ -1451,6 +1454,9 @@ function register_meta( $object_type, $meta_key, $args, $deprecated = null ) { | |||
* @param string $meta_key Meta key. | |||
*/ | |||
$args = apply_filters( 'register_meta_args', $args, $defaults, $object_type, $meta_key ); | |||
if ( isset( $args['label'] ) && ! isset( $args['show_in_rest'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should change before the filter so 3rd party code can still change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when the filter adds a label without setting show_in_rest
? Shouldn't that follow the same behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is safer to move it before the filter as you say to ensure people can change this behavior.
This probably needs a separate track ticket. Similar discussions usually happen there. |
I left one minor note. I'm in favor of that enhancement as it is the feedback we get several times from folks using Block Bindings that they need to remember to enable |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
I've opened a separate ticket for this: https://core.trac.wordpress.org/ticket/62000#ticket. |
I'm pretty strongly against this. Exposing a meta value can be a pretty big footgun. I don't see a compelling reason why we should make that footgun less obvious by conflating the "label" field with whether the meta value is exposed. |
if ( isset( $args['label'] ) && ! isset( $args['show_in_rest'] ) ) { | ||
$args['show_in_rest'] = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( isset( $args['label'] ) && ! isset( $args['show_in_rest'] ) ) { | |
$args['show_in_rest'] = true; | |
} | |
if ( isset( $args['label'] ) && ! isset( $args['show_in_rest'] ) ) { | |
$args['show_in_rest'] = true; | |
} | |
Just adding some spacing for clarity.
I'm sympathetic to the fact that it's easy to forget to enable |
Thank you for the feedback shared so far. In retrospect, I'm not surprised as it indeed could be confusing to learn that |
Isn't that what |
There is no function Anyway, I'm closing this PR for now. Thank you all for valuable feedback. |
I think @TimothyBJacobs was referring to the |
This pull request is built on top of #7298
As suggested by @gziolo here, in this pull request I'm exploring the possibility of setting the
show_in_rest
argument totrue
by default when the new potentiallabel
argument is defined. With the introduction of a new human-readable argument, which hasn't been used before, it could make sense to expose it automatically in the REST API.Basically, these are the use cases:
show_in_rest
is defined, that value is always respected.label
and noshow_in_rest
: It keeps working as before and usesshow_in_rest
false, which is the default. This is a pretty common use case right now.label
and noshow_in_rest
: It setsshow_in_rest
to true. This would be the change introduced.It seems I can't compare against my other branch. The relevant code changes in this PR are:
show_in_rest
: link.Trac ticket: https://core.trac.wordpress.org/ticket/62000
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.